package com.omega.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.omega.constants.ApplicationConstants;
import com.omega.dao.ItemDenominationDao;
import com.omega.entity.ItemDenomination;
import com.omega.service.ItemDenominationService;

@Service
public class ItemDenominationServiceImpl implements ItemDenominationService {

	@Autowired
	ItemDenominationDao denominationDao;

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void addDenomination(ItemDenomination itemDenomination) {
		itemDenomination.setDenominationActive(ApplicationConstants.DENOMINATION_ACTIVE);
		denominationDao.addDenomination(itemDenomination);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public List<ItemDenomination> loadAllDenominations() {
		return denominationDao.listAllDenomination();
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public ItemDenomination loadById(long denominationId) {
		return denominationDao.loadById(denominationId);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void updateDenomination(ItemDenomination form) {
		ItemDenomination denominationEntity = denominationDao.loadById(form
				.getDenominationId());
		denominationEntity.setDenominationName(form.getDenominationName());
		denominationEntity.setMonth(form.getMonth());
		denominationEntity.setYear(form.getYear());
		denominationDao.updateDenomination(denominationEntity);

	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void deactivateDenomination(long denominationId) {
		ItemDenomination denominationEntity = denominationDao
				.loadById(denominationId);
		denominationEntity
				.setDenominationActive(ApplicationConstants.DENOMINATION_INACTIVE);
		denominationDao.updateDenomination(denominationEntity);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void activateDenomination(long denominationId) {
		ItemDenomination denominationEntity = denominationDao
				.loadById(denominationId);
		denominationEntity
				.setDenominationActive(ApplicationConstants.DENOMINATION_ACTIVE);
		denominationDao.updateDenomination(denominationEntity);
	}

}
